﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DisplayBoardInfo.Logger;

namespace DisplayBoardInfo.Server.Forms.Administrator
{
    class Console : TextBox
    {
        public Console()
        {
            InitializeComponent();

            Logger.Logger.Logged += new Logger.Logger.LoggedHandler(Logger_Logged);
        }

        private void Logger_Logged(object sender, LoggerEventArgs args)
        {
            AddMessage(args.LogMessage.ToString());
        }

        private void InitializeComponent()
        {
            this.BackColor = System.Drawing.SystemColors.Window;
            this.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.Multiline = true;
            this.Name = "console";
            this.ReadOnly = true;
            this.Size = new System.Drawing.Size(50, 50);
        }

        public void AddMessage(string message)
        {
            try
            {
                this.Invoke((MethodInvoker)delegate()
                {
                    this.Text += "> " + message + Environment.NewLine;
                });
            }
            catch (InvalidOperationException)
            { 
                //ignore
            }
        }
    }
}
